<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <img src="img/pic_bulboff.gif" alt="电灯泡" id="pub">
    <button type="button" id="btn">开关</button>
    <script src="js/dev/jquery-3.4.1.js"></script>
    <script>
        $(function () {
            $('#btn').on('click',function () {
                if ($('#pub').attr("src").indexOf("off") != -1){
                    console.log("666");
                    $('#pub').attr({src:"img/pic_bulbon.gif"});
                    console.log($('#pub').attr("src"));
                } else if($('#pub').attr("src").indexOf("on") != -1){
                    $('#pub').attr({src:"img/pic_bulboff.gif"});
                }
            })
        })
    </script>
</body>
</html>